package followme.yaohuile.com.followme.adapter.recommend;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

import followme.yaohuile.com.followme.activity.recommend.ViewPagerActivity;

/**
 * Created by Administrator on 15-11-13.
 */
public class RecommendViewPagerAdapter extends PagerAdapter {

    private List<ImageView> list;
    private List<String> viewPagerImgUrl;
    private Context context;

    public RecommendViewPagerAdapter(List<ImageView> list,List<String> viewPagerImgUrl,Context context) {
        this.list = list;
        this.viewPagerImgUrl = viewPagerImgUrl;
        this.context = context;
    }

    @Override
    public int getCount() {
        int ret = 0;
        if (list != null) {
            ret = list.size();
        }
        return ret;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(final ViewGroup container, final int position) {

        list.get(position).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url = viewPagerImgUrl.get(position);
                Intent intent = new Intent(context, ViewPagerActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("url",url);
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
        container.addView(list.get(position));
        return list.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(list.get(position));
    }
}
